package br.uvv.sao.rn;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

import br.uvv.sao.dao.AlunoDAO;
import br.uvv.sao.dao.AlunoOfertaDAO;
import br.uvv.sao.dao.DisciplinaDAO;
import br.uvv.sao.dao.OfertaDisciplinaDAO;
import br.uvv.sao.dao.ProfessorDAO;
import br.uvv.sao.domain.Aluno;
import br.uvv.sao.domain.AlunoOferta;
import br.uvv.sao.domain.Disciplina;
import br.uvv.sao.domain.OfertaDisciplina;
import br.uvv.sao.domain.Professor;
import br.uvv.sao.util.DAOException;

public class OfertaDisciplinaRN implements Serializable {
	
	private static final long serialVersionUID = -2840523452154232015L;
	
	private OfertaDisciplinaDAO ofertaDAO = new OfertaDisciplinaDAO();
	private AlunoDAO alunoDAO = new AlunoDAO();
	private DisciplinaDAO disciplinaDAO = new DisciplinaDAO();
	private ProfessorDAO professorDAO = new ProfessorDAO();
	private AlunoOfertaDAO alunoOfertaDAO = new AlunoOfertaDAO();
	
	public void salvar(OfertaDisciplina ofertaInstance){
		try {
			ofertaInstance.setDisciplina(disciplinaDAO.get(ofertaInstance.getDisciplina().getId()));
			ofertaInstance.setProfessor(professorDAO.get(ofertaInstance.getProfessor().getId()));
			this.ofertaDAO.salvar(ofertaInstance);
		} catch (DAOException e) {
			e.printStackTrace();
		}
	}
	
	public void excluir(OfertaDisciplina ofertaInstance){
		try {
			this.ofertaDAO.excluir(ofertaInstance);
		} catch (DAOException e) {
			e.printStackTrace();
		}
	}
	
	public ArrayList<OfertaDisciplina> listarOferta(Long idDisciplina, Long idProfessor, String semestre, Date ano){
		try {
			return (ArrayList<OfertaDisciplina>)this.ofertaDAO.listar(idDisciplina, idProfessor ,semestre, ano);
		} catch (DAOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public ArrayList<OfertaDisciplina> listarOferta(){
		try {
			return (ArrayList<OfertaDisciplina>)this.ofertaDAO.listar();
		} catch (DAOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public ArrayList<Disciplina> listarDisciplina(String codigo, String nome){
		try {
			return (ArrayList<Disciplina>)this.disciplinaDAO.listar(codigo, nome);
		} catch (DAOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public ArrayList<Aluno> listarAluno(String codigo, String nome, ArrayList<AlunoOferta> alunoOfertaList){
		return (ArrayList<Aluno>)this.alunoDAO.listar(codigo, nome, alunoOfertaList);
	}

	public ArrayList<Professor> listarProfessor(String matricula, String nomeCompleto) {
		return (ArrayList<Professor>) this.professorDAO.listar(nomeCompleto, matricula);
	}
	
	public ArrayList<Disciplina> listarDisciplina(){
		try {
			return (ArrayList<Disciplina>) this.disciplinaDAO.listar();
		} catch (DAOException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public ArrayList<Professor> listarProfessor() {
		return (ArrayList<Professor>) this.professorDAO.listar();
	}

	public ArrayList<AlunoOferta> getAlunoOfertaList(Long id) {
		try {
			return (ArrayList<AlunoOferta>) this.alunoOfertaDAO.listar(id);
		} catch (DAOException e) {
			e.printStackTrace();
			return null;
		}
	}
}
